<script setup>
import { computed } from 'vue'
import { useRoute } from 'vue-router'
import './assets/styles/responsive.css'

/**
 * 获取当前路由信息
 */
const route = useRoute()

/**
 * 计算当前路由名称
 * 用于高亮显示当前选中的导航项
 */
const currentRouteName = computed(() => route.name)

/**
 * 判断导航项是否为当前活跃页面
 * @param {string} routeName - 路由名称
 * @returns {boolean} - 是否为当前活跃页面
 */
const isActive = (routeName) => {
  return currentRouteName.value === routeName
}

/**
 * 导航菜单项配置
 */
const navItems = [
  { name: '首页', icon: 'fa-home', route: { name: 'home' } },
  { name: '饮食', icon: 'fa-utensils', route: { name: 'diet' } },
  { name: '运动', icon: 'fa-dumbbell', route: { name: 'exercise' } },
  { name: '数据', icon: 'fa-chart-line', route: { name: 'tracking' } },
  { name: '我的', icon: 'fa-user', route: { name: 'profile' } }
]
</script>

<template>
  <div class="app-wrapper">
    <div class="content-scroll">
      <div class="app-container">
        <!-- 状态栏 -->
        <div class="status-bar">
          <div class="time">{{ new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }) }}</div>
          <div class="status-icons">
            <i class="fas fa-signal"></i>
            <i class="fas fa-wifi"></i>
            <i class="fas fa-battery-three-quarters"></i>
          </div>
        </div>
        
        <!-- 主内容区域 -->
        <main class="main-content">
          <router-view v-slot="{ Component }">
            <transition name="fade" mode="out-in">
              <component :is="Component" />
            </transition>
          </router-view>
        </main>
        
        <!-- 底部导航栏 -->
        <nav class="tab-bar">
          <router-link
            v-for="item in navItems"
            :key="item.name"
            :to="item.route"
            class="tab-item"
            :class="{ 'active': isActive(item.name) }"
          >
            <i class="fas" :class="item.icon"></i>
            <span class="tab-label">{{ item.name }}</span>
          </router-link>
        </nav>
      </div>
    </div>
  </div>
</template>

<style>
/* 全局CSS变量 */
:root {
  --primary-color: #22C55E;
  --primary-light: #DCFCE7;
  --secondary-color: #16A34A;
  --text-primary: #333333;
  --text-secondary: #6B7280;
  --text-light: #9CA3AF;
  --background-light: #F9FAFB;
  --background-lighter: #F3F4F6;
  --border-color: #f0f0f0;
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 16px;
  --spacing-lg: 24px;
  --spacing-xl: 32px;
  --font-size-xs: 12px;
  --font-size-sm: 14px;
  --font-size-base: 16px;
  --font-size-lg: 18px;
  --font-size-xl: 20px;
  --font-size-2xl: 24px;
  --border-radius-sm: 8px;
  --border-radius-md: 12px;
  --border-radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
  --tab-bar-height: 56px;
}

/* 重置样式 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  font-family: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: var(--text-primary);
  background-color: #f5f5f5;
  overflow-x: hidden;
}

a {
  text-decoration: none;
  color: inherit;
}

/* 应用容器 */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 100%;
  margin: 0 auto;
  position: relative;
}

/* 状态栏样式 */
.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px var(--spacing-md);
  background-color: #ffffff;
  font-size: var(--font-size-sm);
  color: #333;
  height: 24px;
  z-index: 100;
}

.status-bar .status-icons {
  display: flex;
  gap: 6px;
}

/* 主内容区域 */
.main-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: var(--tab-bar-height);
}

/* 底部导航栏 */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--tab-bar-height);
  background-color: white;
  display: flex;
  justify-content: space-around;
  align-items: center;
  border-top: 1px solid var(--border-color);
  z-index: 100;
  box-shadow: 0 -1px 4px rgba(0, 0, 0, 0.05);
}

.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-xs) 0;
  color: var(--text-secondary);
  transition: color 0.2s;
  flex: 1;
  height: 100%;
}

.tab-item i {
  font-size: var(--font-size-lg);
  margin-bottom: var(--spacing-xs);
}

.tab-label {
  font-size: var(--font-size-xs);
  text-transform: capitalize;
}

.tab-item.active {
  color: var(--primary-color);
}

/* 路由过渡动画 */
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.2s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}

/* 平板和桌面布局优化 */
@media (min-width: 768px) {
  .app-container {
    max-width: 768px;
    margin: 0 auto;
    border-left: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
  }
  
  .tab-bar {
    max-width: 768px;
    left: 50%;
    transform: translateX(-50%);
  }
}

@media (min-width: 1024px) {
  .app-container {
    max-width: 1024px;
  }
  
  .tab-bar {
    max-width: 1024px;
  }
  
  .tab-item i {
    font-size: var(--font-size-xl);
  }
  
  .tab-label {
    font-size: var(--font-size-sm);
  }
}
</style>
